package chapter21.others;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by lzy
 * Date: 2018/6/28
 * @author lzy
 */
public class LockDemo {
    private static final Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                lock.lock();
                try {
                    TimeUnit.SECONDS.sleep(10);
                }catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }).start();
            System.out.println("start thread-" + i);
        }

        int a = 1;
    }
}
